#coding=utf-8
'''
Created on 2016 7 20

@author: 403720
'''
import sys
from common import check_detect_connected
sys.path.append('D:\eclipse\luyouqi\src')

import testcase.HiWifi.login_HiWiFi

import time
import ConfigParser
import common.logging_save
import common.machine_connect_wifi    #连接WIFI
import common.check_detect_connected   #检测WIFI是否连接成功
import unittest
import common.assertcheck
import shutil
import os
import testcase.xiaomi
import common.config

class Test(unittest.TestCase):
    def setUp(self):
        common.logging_save.logging.info("设置为5G channel为149")
        print time.ctime(),"设置为5G channel为149"
        self.dDriver = testcase.xiaomi.LoginXiaoMi.Login()
        self.Driver.implicitly_wait(10)
        self.Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div/ul/li[3]/a/span").click()
        time.sleep(1)
        self.Driver.find_element_by_xpath("//a[@href='#!pro/wifi_set']").click()
        time.sleep(2)
        self.Driver.switch_to_frame("setting")
        self.Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[3]/form/div[2]/span/input").click()        
        self.Driver.find_element_by_xpath("/html/body/div[4]/a[10]").click()   #channel149
        time.sleep(2)
        self.Driver.switch_to_default_content()
        self.Driver.find_element_by_xpath("/html/body/div[1]/div/div[3]/div/a[1]/span").click()
        time.sleep(2)
        self.Driver.switch_to_frame("setting")
        self.Driver.find_element_by_xpath("/html/body/div[1]/div[2]/div[3]/form/div[6]/button").click()
        time.sleep(1)
        self.Driver.switch_to_default_content()
        self.Driver.find_element_by_xpath("/html/body/div[1]/div/div[3]/div/a[1]/span").click()
        time.sleep(20)
        self.Driver.quit()
        common.logging_save.logging.info("小米路由器5G网络信道已经设为channel149")
        print time.ctime(),"小米路由器5G网络信道已经设为channel149"
        
    def tearDown(self):
        sys.path.append('\report')
        basic_path = common.config.save_report()
        print basic_path
        different = os.path.join(common.config.save_report(),'Xiaomi','fiveG_149.txt')
        shutil.copyfile(check_detect_connected.save_path,different)
        #self.Driver.quit()

    def testName(self):    #进行连接操作，然后进行判断是否连接成功，如失败则报错
        u"""测试步骤：密码设置为5g channel为149，然后WIFI设备连接路由器   期待结果：可以连接成功，如果连接失败，则直接报错"""

        self.assertEqual('success', common.assertcheck.Test(), "经过检测未连接成功，请排查问题所在")
        common.logging_save.logging.info("检测完毕，可以正常连接WIFI")
        print time.ctime(),"检测完毕，可以正常连接WIFI"

if __name__ == "__main__":
    unittest.main()